﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using BranchWS;


namespace BookstoreDesktopClient {

    public partial class BookstoreClientLogin : Form
    {
        AccountWS.loginReply checkUser;
        AccountWS.AccountWS userData;
        BookstoreClient bookstoreClient;

        public BookstoreClientLogin()
        {
            InitializeComponent();
            userData = new AccountWS.AccountWS();  
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {

            checkUser = userData.login(LoginTextBox.Text, passwordMaskedTextBox.Text); 
            if ((checkUser.role == "admin") || (checkUser.role == "user"))
            {
                bookstoreClient = new BookstoreClient(checkUser.role, checkUser.sessionID);
                bookstoreClient.Show();
                this.Dispose(false);
            }
            else
            {
                MessageBox.Show("Login failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void BookstoreClientLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
